

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Vector;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

public class Suggest {
	private static Vector<String> sample;
	
	public static void main(String[] args) {
		sample = new Vector<String>();
			for (int i = 0; i < 10; i++) {
				sample.add("asdf"+i);
				sample.add("hallo"+i);
				sample.add("test"+i);
				sample.add("abb"+i);
				sample.add("suggest"+i);
				sample.add("field"+i);
			}
		new Suggest();
	}
	
	public Suggest() {

		JFrame f = new JFrame("JSuggestField Test");
			f.setLayout(new GridLayout(4, 1, 5, 5));
			f.setPreferredSize(new Dimension(295, 125));
			f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
			f.setLocation(500, 500);
		f.add(new JLabel("JTextField:"));
		JTextField t = new JTextField();
		f.add(t);
		f.add(new JLabel("JSuggestField:"));
		JPanel p = new JPanel(new BorderLayout());
		p.setMaximumSize(new Dimension(0, 0));
			final JSuggestField s = new JSuggestField(f, sample);
			final JButton drop = new JButton("v");
				drop.addActionListener(new ActionListener() {@Override public void actionPerformed(ActionEvent e) {
					if (!s.isSuggestVisible()) s.showSuggest();
					else s.hideSuggest();
				}});
			p.add(s, BorderLayout.CENTER);
			p.add(drop, BorderLayout.EAST);
		f.add(p);
		f.pack();
		f.setVisible(true);
	}
	
}
